package com.qumitech.visualnovel.controller.rest;

import com.qumitech.visualnovel.model.common.BaseRsp;
import com.qumitech.visualnovel.model.common.ResultEnum;
import com.qumitech.visualnovel.service.robot.RobotService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Auther: jlyin
 * @Date: 2018/12/7 15:01
 * @Description:
 */
@RestController
@RequestMapping("/api/robot")
public class RobotController {
    @Autowired
    private RobotService robotService;

    @RequestMapping(value = "/{user_id}", method = RequestMethod.GET)
    public BaseRsp getVoiceRoom(@PathVariable("user_id") Long uid){
        return robotService.getRobotAccount(uid);
    }

    @RequestMapping(value = "", method = RequestMethod.GET)
    public BaseRsp getVoiceRoom(@RequestParam(value = "type")Integer type,@RequestParam(value = "sub_type")String subType){
        return robotService.getRobotsByType(type, subType);
    }

    @RequestMapping(value = "/excel", method = RequestMethod.POST)
    public BaseRsp importExcel(@RequestParam("file") MultipartFile file){
        robotService.importRobot(file);
        return new BaseRsp(ResultEnum.SUCCESS);
    }

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public BaseRsp getRobotList(@RequestParam(value = "offset",defaultValue = "1") Integer offset,
                                @RequestParam(value = "limit",defaultValue = "10") Integer limit,
                                @RequestParam(value = "sex", required = false) String sex){
        return robotService.getRobotList(offset, limit, sex);
    }

    @RequestMapping(value = "/random", method = RequestMethod.GET)
    public BaseRsp getRobotList(@RequestParam(value = "sex", required = false) String sex){
        return robotService.getRandomRobot(sex);
    }
}
